package com.jiaai.cloud;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.converter.Converter;

import javax.servlet.MultipartConfigElement;
import java.util.Date;

@SpringBootApplication
@MapperScan("com.jiaai.cloud.file.mapper")
public class OaFileManagerApplication {

	public static void main(String[] args) {
		SpringApplication.run(OaFileManagerApplication.class, args);
	}
	/**
	 * 文件上传限制
	 * @return
	 */
	@Bean
	public MultipartConfigElement multipartConfigElement(){
		MultipartConfigFactory factory = new MultipartConfigFactory();
		//设置上传文件大小限制
		factory.setMaxFileSize("10MB");
		//设置上传总数据大小
		factory.setMaxRequestSize("15MB");
		return factory.createMultipartConfig();
	}

	/**
	 * 前端日期格式化
	 * @return
	 */
	@Bean
	public Converter<String, Date> addNewConvert() {
		return new Converter<String, Date>() {
			@Override
			public Date convert(String source) {
				Date date = null;
				date = new Date(Long.parseLong(source));
				return date;
			}
		};
	}
}
